﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.成品出库单.service;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.钉钉
{
    public class 钉钉Service
    {
        /// <summary>
        /// 调拨出库的流程
        /// </summary>
        /// <param name="processStartDTO"></param>
        /// <returns></returns>
        public static String start(ProcessStartDTO processStartDTO)
        {
             return
                RestCall.PostHttp(
                    URL.钉钉url + "/processinstance/start",
                    FunctionHelper.JsonSerialization(processStartDTO)
                );
        }

    }
    public class ProcessStartDTO
    {
        public long agentId { get; set; }
        public String processCode { get; set; }
        public String originatorUser { get; set; }
        public long deptId { get; set; }
        public List<FormComponentValueVo> formComponentValueVoList { get; set; } = new List<FormComponentValueVo>();
        
        /// <summary>
        /// 调拨出库的钉钉流程
        /// </summary>
        /// <param name="调拨出库单Dto"></param>
        /// <param name="fileName"></param>
        public ProcessStartDTO(String offType,StockInOutTitleDTO 调拨出库单Dto, String fileName)
        {
            this.agentId = 1268557914L;
            if (调拨出库类型Consts.平调.Equals(offType))  //  平调
            {
                this.processCode = 调拨流程processCodeConsts.门店processCode;
            }
            else if (调拨出库类型Consts.Luna.Equals(offType)) //  luna
            {
                this.processCode = 调拨流程processCodeConsts.门店processCode;
            }
            else if (调拨出库类型Consts.返厂.Equals(offType)) //  返厂
            {
                //this.processCode = 调拨流程processCodeConsts.工厂processCode;
                this.processCode = 调拨流程processCodeConsts.返厂processCode;
            }
            else if (调拨出库类型Consts.销账.Equals(offType)) //  销账
            {
                this.processCode = 调拨流程processCodeConsts.销账processCode;
            }
            else if (调拨出库类型Consts.抖音出库.Equals(offType)) //  抖音出库
            {
                this.processCode = 调拨流程processCodeConsts.抖音出库processCode;
            }
            else if (调拨出库类型Consts.抖音退货入库.Equals(offType)) //  抖音出库
            {
                this.processCode = 调拨流程processCodeConsts.抖音退货入库processCode;
            }
            else
            {
                this.processCode = 调拨流程processCodeConsts.工厂processCode;
            }
            //this.processCode = "PROC-67D6DDBF-4DDD-448A-81CD-A9755B689984"; //  测试
            this.formComponentValueVoList.Add(new FormComponentValueVo("调拨出库仓库", 调拨出库单Dto.outStoreName));
            this.formComponentValueVoList.Add(new FormComponentValueVo("调拨入库仓库", 调拨出库单Dto.InStoreName));
            this.formComponentValueVoList.Add(new FormComponentValueVo("出库审核人", 调拨出库单Dto.name));
            this.formComponentValueVoList.Add(new FormComponentValueVo("出库单号", 调拨出库单Dto.inOutCode));
            if (!String.IsNullOrEmpty(调拨出库单Dto.remarks))
            {
                this.formComponentValueVoList.Add(new FormComponentValueVo("备注", 调拨出库单Dto.remarks));
            }
            this.formComponentValueVoList.Add(new FormComponentValueVo("日期", 调拨出库单Dto.inOutDate.ToString("yyyy-MM-dd")));
            this.formComponentValueVoList.Add(
                new FormComponentValueVo(
                    "调拨出库单", 
                    "http://192.168.3.33:4545" + URL.出入库单文件路径 + fileName + "\n" + "http://175.170.138.171:4545" + URL.出入库单文件路径 + fileName
                    )
                );
        }
        public ProcessStartDTO build(String originatorUser, long deptId)
        {
            this.originatorUser = originatorUser;
            this.deptId = deptId;
            return this;
        }
    }

    public class 调拨流程processCodeConsts
    {
        public const String 工厂processCode = "PROC-0F5227C7-3CBB-45F4-8AB5-42DD6B88F2C7";//  工厂调拨出库和返厂   ——调拨出库单1
        public const String 门店processCode = "PROC-33004BEC-481A-4028-83D3-C6F8EA9F8A72";//  平调、luna ——调拨出库单2
        public const String 销账processCode = "PROC-FAC406CE-171F-4A3A-B034-2FF0687763B8";//  销账  ——调拨出库单3
        public const String 抖音出库processCode = "PROC-792D34C4-0BD8-4451-926F-AAB1A12AAFED";//  抖音出库
        public const String 抖音退货入库processCode = "PROC-AC55D58C-AD17-4717-B33A-EC4F90B19B99";//  抖音退货入库
        public const String 返厂processCode = "PROC-590AB358-32D1-4D5F-A183-662DFF5163B1";//  返厂
    }
    public class 调拨出库类型Consts
    {
        public const String 平调 = "平调";//  平调
        public const String 返厂 = "返厂";//  返厂
        public const String Luna = "Luna";//  Luna
        public const String 销账 = "销账";//  销账
        public const String 自提 = "自提";//  自提
        public const String 工厂调拨出库 = "工厂调拨出库";//  工厂调拨出库
        public const String 抖音出库 = "抖音出库";//  抖音出库
        public const String 抖音退货入库 = "抖音退货入库";//  抖音退货入库
    }

    public class FormComponentValueVo
    {
        public String name { get; set; }
        public String value { get; set; }
        public FormComponentValueVo(string name, string value)
        {
            this.name = name;
            this.value = value;
        }
    }

}
